package com.yizhi.controller;


import cn.hutool.core.bean.BeanUtil;
import com.yizhi.domain.dto.EvaluationManageDTO;
import com.yizhi.domain.entityDO.EvaluationManageDO;
import com.yizhi.service.IEvaluationManageService;
import com.yizhi.util.ApiResult;
import com.yizhi.util.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 留言表 前端控制器
 * </p>
 *
 * @author zhouyihe
 * @since 2024-04-16
 */
@RestController
@RequestMapping("/evaluation-manage")
@Api(tags = "评价管理控制器")
public class EvaluationManageController {
    private static final Logger log = LoggerFactory.getLogger(EvaluationManageController.class);
    @Autowired
    private IEvaluationManageService evaluationManageService;
    
    /**
     * 添加评价
     * @param evaluationManageDO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("添加评价")
    public ApiResult addEvaluation(@RequestBody EvaluationManageDO evaluationManageDO){
        log.info("添加评价:{}",evaluationManageDO);
        boolean save = evaluationManageService.save(evaluationManageDO);
        return save ? ApiResult.success("添加成功"):ApiResult.error("添加失败");
    }
    
    /**
     * 分页查询
     * @param evaluationManageDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询,条件查询评价")
    public ApiResult<PageResult> pageEvaluation(@RequestBody EvaluationManageDTO evaluationManageDTO) {
        log.info("分页查询,条件查询评价:{}",evaluationManageDTO);
        return ApiResult.success(evaluationManageService.pageQuery(evaluationManageDTO));
    }
    
    /**
     * 删除评价
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    @ApiOperation("根据id单删,或批量删除评论")
    public ApiResult delete(@PathVariable List<Integer> ids) {
        log.info("删除id为:{}的评论",ids);
        boolean b = evaluationManageService.removeBatchByIds(ids);
        return b ? ApiResult.success("删除成功"):ApiResult.error("删除失败");
    }
    
    /**
     * 修改评价
     * @param evaluationManageDTO
     * @return
     */
     @PutMapping()
     @ApiOperation("修改评价")
     public ApiResult updateEvaluation(@RequestBody EvaluationManageDTO evaluationManageDTO){
         log.info("修改评价:{}",evaluationManageDTO);
         EvaluationManageDO EvaluationManage = BeanUtil.copyProperties(evaluationManageDTO, EvaluationManageDO.class);
         boolean save = evaluationManageService.updateById(EvaluationManage);
         return save ? ApiResult.success("修改成功"):ApiResult.error("修改失败");
     }
}
